package com.scoy.honeymei.custem;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * @ClassName: NoViewPage$
 * @Description: 禁止滑动viewpage
 * @Author: GaoZhan
 * @CreateDate: 2019/8/29/0029$ 下午 17:07$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/29/0029$ 下午 17:07$
 * @UpdateRemark: 更新内容
 */

public class NoViewPager extends ViewPager {

    private boolean isCanScroll = false;

    public NoViewPager(Context context) {
        super(context);
    }

    public NoViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setScanScroll(boolean isCanScroll) {
        this.isCanScroll = isCanScroll;
    }

    @Override
    public void scrollTo(int x, int y) {
        super.scrollTo(x, y);
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        if (isCanScroll) {
            return super.onTouchEvent(arg0);
        } else {
            return false;
        }

    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        super.setCurrentItem(item, smoothScroll);
    }

    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if (isCanScroll) {
            return super.onInterceptTouchEvent(arg0);
        } else {
            return false;
        }

    }
}